<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Permissões</title>
        <ui:include src="/WEB-INF/partials/layout/admin/includes.xhtml"/>
    </h:head>
    <h:body>

        <ui:include src="/WEB-INF/partials/layout/admin/menu.xhtml"/>

        <h:form id="crud" prependId="false" >
            <p:dialog widgetVar="removeDialog" modal="true"  id="dialogVar">
                <p:panel id="panelDialog">
                    <h:panelGrid columns="2">
                        <h:outputLabel value="Id:" for="id" />
                        <h:outputText id="id" value="#{PermissaoCrudMB.entity.id}" title="Id" />
                        <h:outputLabel value="Nome:" for="nome" />
                        <h:outputText id="nome" value="#{PermissaoCrudMB.entity.nome}" title="Nome" />
                        <h:outputLabel value="Descricao:" for="descricao" />
                        <h:outputText id="descricao" value="#{PermissaoCrudMB.entity.descricao}" title="Descricao" />
                    </h:panelGrid>
                    <f:facet name="footer">
                        <p:commandButton value="Cancelar" oncomplete="removeDialog.hide()" process="@this"/>
                        <p:commandButton value="Confirmar" action="#{PermissaoCrudMB.delete()}" 
                                         oncomplete="removeDialog.hide()" update="lista" process="panelDialog">
                            <f:param value="#{PermissaoCrudMB.entity.id}" name="id"/>
                        </p:commandButton>
                    </f:facet>
                </p:panel>
            </p:dialog>

            <p:messages autoUpdate="true"/>


            <h1><h:outputText value="Listagem de Permissões"/></h1>

            <p:dataTable value="#{PermissaoCrudMB.lazyDataModel}"  rows="20" var="item"  id="lista" >
                <f:facet name="header">
                    <p:commandButton value="Adicionar" action="#{PermissaoCrudMB.newEntity}"
                                     oncomplete="window.location = './form.xhtml'"/>
                </f:facet>

                <p:column  >
                    <p:commandButton value="Atualizar" onclick="window.location = './form.xhtml?id=#{item.id}'"/>
                    <p:commandButton value="Remover" update="panelDialog" actionListener="#{PermissaoCrudMB.setEntity(item)}"
                                     oncomplete="removeDialog.show()" >
                        <f:param name="id" value="#{item.id}"/>
                    </p:commandButton>
                </p:column>

                <p:column filterBy="#{item.id}" sortBy="#{item.id}" >
                    <f:facet name="header">
                        <h:outputText value="Id"/>
                    </f:facet>
                    <h:outputText value="#{item.id}"/>
                </p:column>

                <p:column filterBy="#{item.nome}" sortBy="#{item.nome}">
                    <f:facet name="header">
                        <h:outputText value="Nome"/>
                    </f:facet>
                    <h:outputText value="#{item.nome}"/>
                </p:column>

                <p:column filterBy="#{item.descricao}" sortBy="#{item.descricao}">
                    <f:facet name="header">
                        <h:outputText value="Descricao"/>
                    </f:facet>
                    <h:outputText value="#{item.descricao}"/>
                </p:column>
            </p:dataTable>
        </h:form>

    </h:body>
</html>

